<template>
  <div class="pd-20">
    <!-- <div class="title">
      <div class="label">风险人群研判条件</div>

    </div> -->
    <!-- <el-card class="header-card">
      <el-form
        ref="filterForm"
        :inline="true"
        :model="queryParams"
        label-width="120px"
      >
        <el-form-item label="体温≥" label-width="55px" prop="bodyTemperature">
          <el-input
            size="mini"
            style="width: 70px"
            v-model.trim="queryParams.bodyTemperature"
            oninput ="value=value.replace(/[^0-9.]/g,'')"
          ></el-input>
          ℃
        </el-form-item>
        <el-form-item label="途径中高风险地区" label-width="180px" prop="passRiskAddr">
          <el-radio-group v-model="queryParams.passRiskAddr">
            <el-radio label="是">是</el-radio>
            <el-radio label="否">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="疫苗" prop="vaccineStatus">
          <el-checkbox-group v-model="queryParams.vaccineStatus">
            <el-checkbox label="加强针">加强针</el-checkbox>
            <el-checkbox label="接种一针、接种两针">接种1针/2针</el-checkbox>
            <el-checkbox label="未接种">未接种</el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item label="健康码" prop="healthCodeStatus">
          <el-checkbox-group v-model="queryParams.healthCodeStatus">
            <el-checkbox label="黄码">黄</el-checkbox>
            <el-checkbox label="红码">红</el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item label=" " prop="nucleicAcidStatusDays">
          无
          <el-input
            oninput ="value=value.replace(/[^0-9.]/g,'')"
            size="mini"
            style="width: 70px"
            v-model.number.trim="queryParams.nucleicAcidStatusDays"
          ></el-input>
          小时内核酸阴性报告
        </el-form-item>
        <el-form-item label=" " prop="antigenStatusDays">
          无
          <el-input
            oninput ="value=value.replace(/[^0-9.]/g,'')"
            size="mini"
            style="width: 70px"
            v-model.number.trim="queryParams.antigenStatusDays"
          ></el-input>
          小时内抗原阴性报告
        </el-form-item>
      </el-form>
      <div class="btn">
        <el-button size="small" type="primary" @click="handleSearch"
          >查询</el-button
        >
        <el-button size="small" type="primary" @click="handleReset"
          >重置</el-button
        >
      </div>
    </el-card> -->
    <div class="add-row">
      <label>高风险判断条件 <el-button type="primary" size="small" @click="$router.go(-1)">返回</el-button></label>
      <el-button type="primary" size="small" @click="handleAdd">新增+</el-button>
    </div>
    <acc-table :tableData="tableData" :columnDefs="columnDefs">
        <template #order={index}>
          <span>{{index | orderIndex(pageVo)}}</span>
        </template>
        <template #passRiskAddr={row}>
          <span>{{row.passRiskAddr === '是' || row.passModerateAddr === '是' ? '是' : row.passRiskAddr || row.passModerateAddr ? '否' : ''}}</span>
        </template>
        <template #status={row}>
          <span>{{row.status === 1 ? '已启用' : '未启用'}}</span>
        </template>
        <template #action={row}>
          <el-button size="mini" type="text" @click="handleLook(row)">查看</el-button>
          <el-button size="mini" type="text" @click="handleEdit(row)">编辑</el-button>
          <el-button size="mini" type="text" @click="handleDel(row)">删除</el-button>
          <el-button size="mini" v-if="row.status === 0" type="text" @click="handleStart(row)">启用</el-button>
          <el-button size="mini" v-else-if="row.status === 1" type="text" @click="handleBan(row)">禁用</el-button>
        </template>
    </acc-table>
    <acc-page :total='total' :page-size='pageVo.pageSize' :current-page='pageVo.pageNum'  @current-change='handleChangePage' @size-change='handleChangeSize'></acc-page>
    <el-drawer
      :visible.sync="visibleDrawer"
      :wrapper-closable='false'
      show-slose
      size='45%'>
      <NewPage v-if="visibleDrawer" :drawerData='drawerData' @click-cancel='handleCancel'></NewPage>
    </el-drawer>
  </div>
</template>

<script>
import { columnDefs } from './mock'
import NewPage from './new.vue'
import { getPreventionRiskRulesList, deletePreventionRiskRules, isEffectivePreventionRiskRules, refreshRiskScreenData } from '@/views/children/antiepidemic/js/preventionRiskScreen'
export default {
  components: { NewPage },
  data () {
    return {
      visibleDrawer: false,
      queryParams: {
        healthCodeStatus: [],
        vaccineStatus: []
      },
      columnDefs: [],
      tableData: [],
      pageVo: {
        pageNum: 1,
        pageSize: 10
      },
      total: 0,
      drawerData: {
        type: 'add',
        id: null
      },
      tenantNo: ''
    }
  },
  created () {
    this.columnDefs = columnDefs
  },
  mounted () {
    let userInfo = localStorage.getItem('Standard__User-Info')
    this.tenantNo = JSON.parse(userInfo).value.tenantNo
    this.handleSearch()
  },
  methods: {
    handleReset () {
      this.queryParams = {
        healthCodeStatus: [],
        vaccineStatus: []
      }
    },
    handleSearch () {
      this.pageVo.pageNum = 1
      this.loadDataList()
    },
    loadDataList () {
      let temp = {}
      Object.assign(temp, this.queryParams, this.pageVo)
      if (temp.healthCodeStatus.length === 0) delete temp.healthCodeStatus
      if (temp.vaccineStatus.length === 0) {
        delete temp.vaccineStatus
      } else {
        temp.vaccineStatus = temp.vaccineStatus.join('、').split('、')
      }
      temp.tenantNo = this.tenantNo
      getPreventionRiskRulesList(temp).then(res => {
        this.tableData = res.data.records || []
        this.total = res.data.total
      })
    },
    handleChangePage (page) {
      this.pageVo.pageNum = page
      this.loadDataList()
    },
    handleChangeSize (size) {
      this.pageVo.pageSize = size
      this.handleSearch()
    },
    handleAdd () {
      this.drawerData.type = 'add'
      this.visibleDrawer = true
    },
    handleLook (row) {
      this.drawerData.type = 'look'
      this.drawerData.id = row.id
      this.visibleDrawer = true
    },
    handleEdit (row) {
      this.drawerData.type = 'edit'
      this.drawerData.id = row.id
      this.visibleDrawer = true
    },
    handleCancel (val) {
      if (val === 'add') this.handleSearch()
      else if (val === 'edit') this.loadDataList()
      this.visibleDrawer = false
    },
    handleDel (row) {
      this.$confirm('是否删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deletePreventionRiskRules({ id: row.id }).then(() => {
          this.$message.success('删除成功')
          this.loadDataList()
        })
      }).catch(() => {})
    },
    handleStart (row) {
      this.$confirm('是否启用?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        isEffectivePreventionRiskRules({ id: row.id, type: 1, tenantNo: this.tenantNo }).then(() => {
          this.$message.success('启用成功')
          this.RefreshData(row.roleCode)
        })
      }).catch(() => {})
    },
    RefreshData (roleCode) {
      if (!roleCode) return
      refreshRiskScreenData({ roleCode }).finally(res => {
        this.loadDataList()
      })
    },
    handleBan (row) {
      this.$confirm('是否禁用?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        isEffectivePreventionRiskRules({ id: row.id, type: 0, tenantNo: this.tenantNo }).then(() => {
          this.$message.success('禁用成功')
          this.loadDataList()
        })
      }).catch(() => {})
    }
  }
}
</script>

<style lang='scss' scoped>
.title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
}
.add-row {
  display: flex;
  justify-content:space-between;
  align-items: center;
  margin-bottom: 10px;
  label {
    font-size: 18px;
    font-weight: 600;
  }
}
.btn {
  text-align: center;
}
</style>
